package com.yintao.ytframe.base.design.factory.dest.impl;

import com.yintao.ytframe.base.design.factory.dest.IAwardService;
import com.yintao.ytframe.base.design.factory.normal.bo.AwardReq;
import com.yintao.ytframe.base.design.factory.normal.bo.AwardRes;
import com.yintao.ytframe.base.design.factory.normal.bo.DeliverReq;
import com.yintao.ytframe.base.design.factory.normal.rpc.GoodsRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @Description
 * @Author yintao12
 * @Date 2021/1/4 20:29
 * @Doc
 **/
public class GoodsAwardServiceImpl implements IAwardService {

    private static final Logger log = LoggerFactory.getLogger(GoodsAwardServiceImpl.class);

    private GoodsRpcService goodsRpcService = new GoodsRpcService();

    public AwardRes awardUser(String uid, String couponNumber, String uuid, Map<String, String> extMap) throws Exception {
        //组装参数
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setAddress(queryUserAddress(uid));
        deliverReq.setSkuNo(queryAwardSku(uid));
        deliverReq.setUid(uid);
        log.info("GoodsAwardServiceImpl -> awardUser start, uid={}, couponNumber={}, uuid={}, extMap={}", uid, couponNumber, uuid, extMap);
        Boolean aBoolean = goodsRpcService.deliverGoods(deliverReq);
        if (aBoolean) {
            log.info("GoodsAwardServiceImpl -> awardUser end, result={}", aBoolean);
            return AwardRes.buildSuccessMsg();
        }
        throw new Exception("发送实物奖品失败");
    }

    private String queryAwardSku(String uid) {
        return "12312412";
    }

    private String queryUserAddress(String uid) {
        return "北京市大兴区";
    }


}
